/**
* Created by wust on 2020-04-26 08:54:23.
*/
<template>
  <el-form ref="formModel" :model="formModel" :rules="rules" label-width="120px" style="width:70%;"
    @submit.native.prevent>
    <el-form-item label="name" prop="name">
      <el-input v-model="formModel.name"></el-input>
    </el-form-item>
    <el-form-item label="group_name" prop="groupName">
      <el-input v-model="formModel.groupName"></el-input>
    </el-form-item>
    <el-form-item label="master_slave" prop="masterSlave">
      <el-input v-model="formModel.masterSlave"></el-input>
    </el-form-item>
    <el-form-item label="jdbc_url" prop="jdbcUrl">
      <el-input v-model="formModel.jdbcUrl"></el-input>
    </el-form-item>
    <el-form-item label="jdbc_username" prop="jdbcUsername">
      <el-input v-model="formModel.jdbcUsername"></el-input>
    </el-form-item>
    <el-form-item label="jdbc_password" prop="jdbcPassword">
      <el-input v-model="formModel.jdbcPassword"></el-input>
    </el-form-item>
    <el-form-item label="jdbc_driver" prop="jdbcDriver">
      <el-input v-model="formModel.jdbcDriver"></el-input>
    </el-form-item>
    <el-form-item label="description" prop="description">
      <el-input v-model="formModel.description"></el-input>
    </el-form-item>
    <el-form-item label="agent_id" prop="agentId">
      <el-input v-model="formModel.agentId"></el-input>
    </el-form-item>

    <el-form-item style="text-align: left;">
      <el-button type="primary" @click="onSubmit('formModel')" :loading="submitting">提交</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
  import Vue from 'vue'

  export default {
    name: 'data-source-create',
    data() {
      return {
        submitting: false,
        formModel: {
          name: null,
          groupName: null,
          masterSlave: null,
          jdbcUrl: null,
          jdbcUsername: null,
          jdbcPassword: null,
          jdbcDriver: null,
          description: null,
          agentId: null,

        },
        rules: {}
      }
    },
    methods: {
      onSubmit: function(formData) {
        this.$refs[formData].validate((valid) => {
          if (!valid) {} else {
            this.submitting = true
            Vue.$ajax({
              method: 'post',
              url: Vue.$adminServerURL + '/web/v1/DataSourceController',
              data: this.formModel
            }).then(res => {
              this.submitting = false
              if (res.data.flag !== 'SUCCESS') {
                if (!Vue.$isNullOrIsBlankOrIsUndefined(res.data.message)) {
                  this.$message({
                    message: res.data.message,
                    type: 'warning'
                  })
                }
              } else {
                this.$message({
                  message: res.data.message,
                  type: 'success'
                })
                this.resetForm('formModel')
              }
            })
          }
        })
      },
      resetForm(formData) {
        this.$refs[formData].resetFields()
      }
    }
  }
</script>
